package test.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;

import org.apache.log4j.Logger;

import android.os.HandlerThread;


public class MyServer {
	
	public static ArrayList<Socket> socketList = new ArrayList<Socket>();
//	private static ServerSocket server;
	private static final Logger LOG = Logger.getLogger(MyServer.class);
	private static final int PORT = 12345;
	private ServerSocket serverSocket;
	

	public static void main(String[] args) throws IOException {
		LOG.info("Socket programe is starting...");
//		server = new ServerSocket(8337);
//		  
//        // 循环接受客户端的请求  
//        while (true) {
//            // 此行代码将阻塞，将一直等待客户端的请求  
//            Socket socket = server.accept();  
//            socketList.add(socket);
//            SocketAddress clientAddress=socket.getRemoteSocketAddress();
//			System.out.println("Handling client at "+clientAddress);
//            // 每接受一个客户端的请求，则打开一个线程
//            new Thread(new ServerThread(socket)).start();
//       }
	}
	
	public void init() {
		try {
			serverSocket = new ServerSocket(PORT);
			while(true) {
				Socket client = serverSocket.accept();
				new Thread(new ServerThread(client)).start();
			}
		} catch (Exception e) {
			LOG.info("Server is not good well :" + e.getMessage());
		}
	}
}